package com.yisu.auction.api.core.service.impl;

import com.yisu.auction.api.core.mapper.NewActivitiesMapper;
import com.yisu.auction.api.core.mapper.PrizeMapper;
import com.yisu.auction.api.core.mapper.RechargeMapper;
import com.yisu.auction.api.core.service.INewActivitiesService;
import com.yisu.auction.api.domain.request.rechargePackage.RechargeRequest;
import com.yisu.auction.ewf.entity.NewActivities;
import com.yisu.auction.ewf.entity.Prize;
import com.yisu.auction.ewf.entity.Recharge;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * author: 赵杰
 * Business Description：
 * createTime：2017/9/9
 */
@Service("INewActivitiesService")
public class NewActivitiesServiceImpl implements INewActivitiesService {
    @Resource
    private PrizeMapper prizeMapper;
    @Resource
    private RechargeMapper rechargeMapper;
    @Resource
    private NewActivitiesMapper newActivitiesMapper;

    /**
     * author: 赵杰
     * Business Description：获取新手活动竞品详情
     *
     * @return
     */
    @Override
    public Prize getNewActivitiesPrize() {
        return prizeMapper.getNewActivitiesPrize();
    }

    /**
     * author: 赵杰
     * Business Description：创建充值订单
     *
     * @param rechargeRequest
     * @return
     */
    @Override
    public String createRechargeOrder(RechargeRequest rechargeRequest) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");//临时编号
        String orderId = rechargeRequest.getOrderSign() + simpleDateFormat.format(new Date());
        Recharge insertModel = new Recharge();
        insertModel.setCreateDate(new Date());
        insertModel.setIsValid(true);
        insertModel.setType(rechargeRequest.getPayType());
        insertModel.setMoney(new BigDecimal(rechargeRequest.getAmount()));
        insertModel.setSysType(rechargeRequest.getAppType());
        insertModel.setStatus(0);
        insertModel.setOrderNo(orderId);
        insertModel.setMemberId(Long.valueOf(rechargeRequest.getMemberId()));
        insertModel.setObjDesc(rechargeRequest.getDescription());
        NewActivities newActivities = new NewActivities();
        newActivities.setCreateDate(new Date());
        newActivities.setMemberId(Long.valueOf(rechargeRequest.getMemberId()));
        newActivities.setPrizeId(Long.valueOf(rechargeRequest.getDescription()));
        newActivities.setRechargeObj(rechargeRequest.getAmount());
        newActivitiesMapper.insertSelective(newActivities);
        if (rechargeMapper.insertSelective(insertModel) > 0) {
            return orderId;
        } else {
            return "";
        }
    }
}
